<template>

    <input type="text" v-model="name">
</template>

<script lang="ts" setup>
import {ref, watch} from "vue";


const name = useStorage("n")

watch(name, (newValue) => {
    console.log(`数据变化了，newValue值是${newValue}`);
    sessionStorage.setItem('n', newValue)
})


function useStorage(n:string) {
    const name = ref(sessionStorage.getItem("n") ?? "");
    watch(name, (newValue) => {
        console.log(`数据变化了，newValue值是${newValue}`);
        sessionStorage.setItem(n, newValue)
    })
    return name;
}
</script>

<style scoped>

</style>
